<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>渠道列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="__PUBLIC__/admin/favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
</head>
<include file="Admin@Index:cache" />
<body class="gray-bg contacts">
<style>
    .table-hover>tbody>tr>td{
        height:4rem;
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight" oncopy="copyval()">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>渠道列表</h5>
                    <div class="ibox-tools">
                        <a href="javascript:;" class="btn btn-success btn-xs" onclick="apply('','','','','','',0,'')" >创建渠道</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <!--<div class="col-sm-12" style="margin-bottom: 1rem">
                        <form role="form" action="__SELF__" method="get">
                            <div class="form-group">
                                <input type="text" id="content" placeholder="" name="content" class="form-control">
                            </div>
                            <div>
                                <select name="state" id="state" class="form-control m-b"  style="margin-bottom: 0;padding-top: 3px;display: inline;width: 10%;" >
                                    <option value="">状态</option>
                                    <option value="1" <if condition="$_GET['state'] eq 1">selected</if>>未使用</option>
                                    <option value="2" <if condition="$_GET['state'] eq 2">selected</if>>已使用</option>
                                </select>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit" id="search"><strong>搜索</strong></button>
                            </div>
                        </form>
                    </div>-->
                    <br>
                    <table class="table table-striped table-hover">
                        <tbody>
                        <tr>
                            <th>渠道名</th>
                            <th width="100px">渠道推广链接</th>
                            <th>商家编码</th>
                            <th>样式</th>
                            <th width="240px">备注</th>
                            <th>出借人</th>
                            <th >流量单价</th>
                            <th>创建时间</th>
                            <th>状态</th>
                            <th class="client-status" width="260px">操作</th>
                        </tr>
                        <foreach name="list" item="list">
                            <tr>
                                <td><{$list.channel_name}></td>
                                <td id="link_<{$list.id}>"><div><{$list.link}></div></td>
                                <td><{$list.shop_identifier}></td>
                                <td><{$list.title}></td>
                                <td><{$list.remark}></td>
                                <td><{$list.lender}></td>
                                <td><{$list.flow_price}></td>
                                <td><{$list.ctime}></td>
                                <td>
                                    <switch name="list.state">
                                        <case value="1">下架</case>
                                        <case value="2">上架</case>
                                    </switch>
                                </td>
                                <td class="client-status">
                                    <a class="btn btn-info btn-rounded " href="javascript:void(0);" onclick="apply('<{$list.channel_name}>','<{$list.style_id}>','<{$list.remark}>','<{$list.shop_id}>','<{$list.chan_id}>','<{$list.state}>',1,'<{$list.server_id}>','<{$list.flow_price}>')">编辑</a>
                                    <!--<a class="btn btn-danger btn-rounded" rid="<{$list.id}>" href="javascript:void(0);" onclick="del('<{$list.chan_id}>');" >删除</a>-->
                                    <a class="btn btn-primary btn-rounded" rid="<{$list.id}>" href="javascript:void(0);"  onclick="copyUrl('<{$list.link}>')">复制链接</a>
                                    <a class="btn btn-white btn-rounded" rid="<{$list.id}>" href="javascript:void(0);" onclick="qrcode('<{$list.code_picture}>');" >查看二维码</a>
                                </td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                    <ul class="pagination">
                        <if condition="$tol gt 10">
                            <{$fpage}>
                        </if>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__PUBLIC__/admin/js/layer/layer.js"></script>
<script src="__PUBLIC__/admin/js/layui/layui.js"></script>
<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
<script src="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.js"></script>
<script src="__PUBLIC__/admin/js/clipboard.js"></script>
<script>
    function copyUrl(url) {
        var clipboard = new ClipboardJS('.btn', {
            text: function() {
                return url;
            }
        });
        clipboard.on('success', function(e) {
            layer.msg('已经复制到剪切板',{icon:6,time:2000});
            clipboard.destroy();
        });
        clipboard.on('error', function(e) {
            layer.msg('复制失败',{icon:5,time:2000});
        });
    }

    $(document).ready(function () {
        $('.contact-box').each(function () {
            animationHover(this, 'pulse');
        });
    });

    $(document).ready(function () {
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
    });

    function qrcode(url){
        var html='';
        html+='<div class="modal-body" id="lists" style="height:100%">';
        html+='<form class="form-horizontal">';
        html+='<div class="form-group">';
        html+='<div class="col-sm-8" >';
        html+='<img src="'+url+'" style="width: 300px;height: 300px">';
        html+='</div>';
        html+='</div>';
        html+='</form>';
        html+='</div>';
        layer.open({
            type: 1, //Page层类型
            area: ['360px', '400px'],
            title: '查看二维码',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });

    }

    function apply(channel_name,style_id,remark,shop_id,chan_id,state,n,lender_id,flow_price){
        var str='selected';
        var ss='<{$shop_style}>';
        var sk='<{$shopkeeper}>';
        var ld='<{$lender}>';
        var shop_style=JSON.parse(ss);
        var shopkeeper=JSON.parse(sk);
        var lender=JSON.parse(ld);
//        console.log(service_market);
        html='';
        html+='<div class="modal-body" id="lists" style="height:100%">';
        html+='<form class="form-horizontal">';
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label" >渠道名：</label>';
        html+='<div class="col-sm-8">';
        html+='<input type="text" id="channel_name"  value="'+channel_name+'" placeholder="渠道名" class="form-control">';
        html+='</div>';
        html+='</div>';
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label">选择样式：</label>';
        html+='<div class="col-sm-8">';
        html+='<select class="form-control m-b" name="style_id" id="style_id" style="height:3rem">';
        for(var i=0;i<shop_style.length;i++){
            html+='<option value="'+shop_style[i].id+'"';
            if(shop_style[i]['id']==style_id){
                html+=' selected';
            }
            html+='>'+shop_style[i]['title']+'</option>';
        }
        html+='</select>';
        html+='</div>';
        html+='</div>';
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label" >备注：</label>';
        html+='<div class="col-sm-8">';
        html+='<textarea style="height:10rem" type="text" id="remark" placeholder="" class="form-control" >'+remark+'</textarea>';
        html+='</div>';
        html+='</div>';
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label">指定客服：</label>';
        html+='<div class="col-sm-8">';
        html+='<select class="form-control m-b" name="shop_id" id="shop_id" style="height:3rem">';
        for(var i=0;i<shopkeeper.length;i++){
            html+='<option value="'+shopkeeper[i].id+'"';
            if(shopkeeper[i]['id']==shop_id){
                html+=' selected';
            }
            html+='>'+shopkeeper[i]['name']+'</option>';
        }
        html+='</select>';
        html+='</div>';
        html+='</div>';

        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label">选择出借人：</label>';
        html+='<div class="col-sm-8">';
        html+='<select class="form-control m-b" name="server_id" id="server_id" style="height:3rem">';
        html+='<option value="0">请选择出借人</option>';
        for(var i=0;i<lender.length;i++){
            html+='<option value="'+lender[i].id+'"';
            if(lender[i]['id']==lender_id){
                html+=' selected';
            }

            html+='>'+lender[i]['name']+'</option>';
        }
        html+='</select>';
        html+='</div>';
        html+='</div>';


        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label" >流量单价：</label>';
        html+='<div class="col-sm-8">';
        html+='<input type="number" id="flow_price"  value="'+flow_price+'" placeholder="流量单价" class="form-control">';
        html+='</div>';
        html+='</div>';


        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label">上架状态：</label>';
        html+='<div class="col-sm-8">';
        html+='<select class="form-control m-b" name="state1" id="state1" style="height:3rem">';
        html+='<option value="1" ';
        if(state==1){
            html+= str;
        }
        html+='>下架</option>>';
        html+='<option value="2" ';
        if(state==2){
            html+= str;
        }
        html+='>上架</option>>';
        html+='</select>';
        html+='</div>';
        html+='</div>';
        html+='</form>';
        html+='<div class="modal-footer" style="border:0">';
        html+='<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';



        if(n==1){
            html+='<a href="javascript:void(0);" onclick="applys(\''+chan_id+'\',1);" type="button" class="btn btn-primary" >修改</a>';
        }else{
            html+='<a href="javascript:void(0);" onclick="applys(\''+chan_id+'\',0);" type="button" class="btn btn-primary" >添加</a>';
        }
        html+='</div>';
        html+='</div>';



        layer.open({
            type: 1, //Page层类型
            area: ['530px', '550px'],
            title: '编辑渠道',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }
    var op=1;
    var picop=1;
    function applys(chan_id,n){
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        var channel_name=$('#channel_name').val();
        var flow_price=$('#flow_price').val();
        var remark=$('#remark').val();
        var shop_id=$("#shop_id option:selected").val();
        var style_id=$("#style_id option:selected").val();
        var state=$("#state1 option:selected").val();
        var server_id=$("#server_id option:selected").val();
        if(server_id==""){
            layer.close(index);
            layer.msg('请选择出借人',{icon:5,time:2000});
            return false;
        }
        if(channel_name==""){
            layer.close(index);
            layer.msg('渠道不能为空',{icon:5,time:2000});
            return false;
        }
        if(style_id==""){
            layer.close(index);
            layer.msg('请选择样式',{icon:5,time:2000});
            return false;
        }
        if(n==1){
            if(chan_id==""){
                layer.close(index);
                layer.msg('渠道id不能为空',{icon:5,time:2000});
                return false;
            }
        }
        layer.confirm('确定要编辑渠道数据吗？', {
            btn: ['确定','取消'] //按钮
        },function(){
            $.post('__MODULE__/Operate/cpa_edit',{channel_name:channel_name,chan_id:chan_id,remark:remark,shop_id:shop_id,style_id:style_id,state:state,lender_id:server_id,flow_price:flow_price},function(data){
                layer.closeAll();
                if(data.code=='1001'){
                    window.location.reload();
                }else{
                    if(data.status=='0'){
                        layer.msg(data.info,{time:2000,icon:5});
                    }else{
                        layer.msg(data.result,{time:2000,icon:5});
                    }
                }
            });
        }, function(){
            layer.close(index);
        });
    }

    //删除
    function del(chan_id){
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        layer.confirm('是否确定删除渠道',function(){
            $.post('__MODULE__/Operate/delcpa',{chan_id:chan_id},function(data){
                layer.closeAll();
                if(data.code=='1001'){
                    window.location.reload();
                }else{
                    if(data.status=='0'){
                        layer.msg(data.info,{time:2000,icon:5});
                    }else{
                        layer.msg(data.result,{time:2000,icon:5});
                    }
                }
            });
        });
    }


    function copyval() {
//        event.returnValue = false;
        var content = window.getSelection().toString();
        $.post('__MODULE__/Mypublic/copy_all', {content:content}, function (data) {
            if (data.code == '1001') {
            } else {
                console.log(data);
            }
        });
//        console.log(content)
    }
</script>


</body>

</html>
